<template>
	<div>
		<zbTable ref="tableRef" :api-fun="get_list" @action="action"></zbTable>
		<!-- 新增/编辑弹窗 -->
		<user-edit v-if="showEdit" v-model:visible="showEdit" :actionStatus="actionStatus" :editData="editData" @done="done" />
		<!-- 审核弹窗 -->
		<check-data v-if="showCheck" v-model:visible="showCheck" :editData="editData" @done="done" />
		<reject
		v-if="addShow"
		v-model:visible="addShow"
		@done="getNewList"
		/>
		<accpets
		v-if="accpetShow"
		v-model:visible="accpetShow"
		:Code="editData"
		@done="receive"
		/>
	</div>
</template>

<script setup>
import { ref,onMounted} from 'vue';
import { message, Modal } from 'ant-design-vue';
import { useRouter } from 'vue-router';
import { actionFn } from '@/utils/action.js';
import { daochuFn } from '@/utils/daochu.js';
import { PlusOutlined, UploadOutlined,ClearOutlined} from '@ant-design/icons-vue';
// import zbTable from '@/components/zbTable/jewelryIndex.vue';
import zbTable from '@/components/zbTable/receiptsStoreIndex.vue';
import userEdit from './components/user-edit.vue';
import checkData from './components/check-data.vue';
import reject from './components/reject.vue';
import accpets from './components/accpets.vue';
import {cancel_purchase, del_receipts, back_verify, cancel_verify} from '@/api/jewelry/receipts_distribute';
import { get_list,confirm_receive} from '@/api/jewelry/receipts_store_enter';
// 是否显示编辑弹窗
const showEdit = ref(false);
const showCheck = ref(false);
const addShow = ref(false);
const accpetShow = ref(false);
// 编辑数据
const editData = ref({});
// 编辑按钮数据
const actionData = ref({});
// 获取子组件
const tableRef = ref(null);
const optBtn = ref([]);
const actionStatus = ref('add');
const router = useRouter();
  const { push } = useRouter();
  onMounted(() => {

  });
/* 打开编辑弹窗 */
const action = data => {
	console.log("操作",data.action_data.type)
	editData.value.id = data.row_data.id;
	editData.value.code = data.row_data.code;//单据号
	editData.value.to_type_code = data.row_data.to_type_code;//门店单号
	actionData.value = data.action_data;
	if (data.action_data.type == 'edit') {
		showEdit.value = true;
		actionStatus.value = 'edit';
	}else if (data.action_data.type == 'verify') {
		showCheck.value = true;
	}else if (data.action_data.type == 'reject') {
		addShow.value = true;
	}else if (data.action_data.type == 'agree') {
		accpetShow.value = true;
	}else if (data.action_data.type == 'detail') {
		toDetail(data.row_data);
	}
};
const toDetail = (record) => {
    console.log('看详情');
    let r = router.currentRoute.value.path.split('/');
    let newUrl = `/${r[1]}/${r[2]}/detail`;
    console.log('newUrl', newUrl);
    push({
      path: newUrl,
      query: { code: record.code }
    });
  };
//接收
const receive =(val)=>{
	console.log('接受',val)
	confirm_receive({ code: editData.value.code,receive_status:1,store_group_code:val})
		.then(res => {
			reloadTable();
			message.success(res.msg);
		})
		.catch(e => {
			reloadTable();
			message.error(e);
		});
}
//拒绝
const getNewList =(val)=>{
	console.log('拒绝',editData.value.code)
	confirm_receive({ code: editData.value.code,receive_status:2,receive_cause:val})
		.then(res => {
			message.success(res.msg);
			reloadTable();
			addShow.value = false;
		})
		.catch(e => {
			message.error(e);
		});
}
const done = form => {
	actionFn(actionData.value, form, reloadTable);
};
const reloadTable = () => {
	showEdit.value = false;
	showCheck.value = false;
	tableRef.value.reload();
};
const daochu = ()=>{
	  let data = {
		  url:'warehouse/receipts_store_enter/export',
		  params:{},
		  filename:'门店调拨入库列表'
	  }
	  daochuFn(data);
	};
</script>
